<template>
	<view>
		<view class="top">
			<span @click="goback"><</span>
			<span>电子书列表</span>
		</view>
		<view class="list">
			<view class="list_item" v-for="(item,index) in booklist" :key="item.id" @click="detail">
				<view class="left">
					<image :src="item.cover" mode=""></image>
				</view>
				<view class="right">
					<h4>{{item.title}}</h4>
					<p>
						<span>￥{{item.price}}<font color="#ccc" size="2">￥{{item.t_price}}</font></span>
						<view class="quan">
							<span>{{item.sub_count}}人订阅</span>
							<span class="iconfont icon-youjiantou"></span>
						</view>
					</p>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {getBook} from "@/api/book.js"
	export default {
		data() {
			return {
				booklist:[],
				query:{
					page:1,
					limit:10
				},
				total:0,
				isloading:false
			};
		},
		onLoad: function (options) {
			this.getbooklist()
			setTimeout(function () {
				console.log('start pulldown');
			}, 1000);
				uni.startPullDownRefresh();
			},
			onPullDownRefresh() {
				console.log('refresh');
				setTimeout(function () {
					uni.stopPullDownRefresh();
				}, 1000);
			},
			//上拉加载
			onReachBottom() {
				console.log("到底了");
				if(this.query.page<this.total){
				    this.query.page++
				    this.getbooklist()
				}else{
				    uni.showToast({
				    title: '到底了',
				    })
				}
					
			},
		methods:{
			//跳转
			detail(){
				uni.navigateTo({
					url:"/pages/book-detail/book-detail"
				})
			},
			//获取数据
			getbooklist(){
				getBook(this.query).then(res=>{
					console.log(this.query);
					this.booklist=[...this.booklist,...res.data.rows];
					this.total=res.data.count
					console.log(this.booklist);
				})
			},
			//返回
			goback(){
				uni.switchTab({
					url:'/pages/index/index'
				})
			}
		}
	}
</script>

<style lang="scss">
.top{
	width: 100%;
	height: 100rpx;
	display: flex;
	align-items: center;
	font-weight: bold;
	background-color: #fff;
	:nth-child(1){
		margin-left: 30rpx;
		font-size: 50rpx;
	}
	:nth-child(2){
		margin-left: 260rpx;
	}
}
.list{
	width: 100%;
	height: 274rpx;
	.list_item{
		display: flex;
		.left{
			width: 184rpx;
			height: 234rpx;
			margin: 20rpx;
			image{
				width: 100%;
				height: 100%;
			}
		}
		.right{
			margin-top: 20rpx;
			width: 500rpx;
			height: 234rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			p{
				display: flex;
				justify-content: space-between;
				span{
					color: red;
					font-size: 35rpx;
				}
				.quan{
					width: 200rpx;
					height: 50rpx;
					border: 2rpx solid #ccc;
					border-radius: 40rpx;
					span{
						color: #000;
						font-size: 30rpx;
						margin-left: 15rpx;
					}
				}
			}
		}
	}
}
</style>
